package edu.ncst.baseweb.service.impl.admin;

import cn.wintersun.basecommon.common.Result;
import edu.ncst.baseweb.dao.UserType;
import edu.ncst.baseweb.dao.web.Admin;
import edu.ncst.baseweb.mapper.*;
import edu.ncst.baseweb.service.intrer.admin.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestPart;

import java.util.ArrayList;
import java.util.List;

@Service
public class AdminImpl implements AdminService {
    @Autowired
    private EquMapper equMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private LabInfoMapper labInfoMapper;

    @Autowired
    private UserRolesMapper userRolesMapper;
    @Autowired
    private RolesMapper rolesMapper;
    public Result<List<Object>> list(@RequestPart String a) {

        List<Admin> listAdmin = new ArrayList<>();
        //添加用户数量 实验室动态数量 等
        listAdmin.add(new Admin(
                userMapper.getCount(),//用户总数
                equMapper.getCount(),//设备总数
                labInfoMapper.getCount(),//动态总数
                equMapper.getInCount(),//在库数量
                equMapper.getOutCount(),//接触数量
                equMapper.getRepairEquNumber()));//维修中数量
        List<UserType> typeList = new ArrayList<>();
        //添加各个用户的人数
        typeList.add(new UserType(userRolesMapper.countUserRolesByRoleId(rolesMapper.getRoleNameId("系统管理员")),
                userRolesMapper.countUserRolesByRoleId(rolesMapper.getRoleNameId("本科生")),
                userRolesMapper.countUserRolesByRoleId(rolesMapper.getRoleNameId("研究生")),
                userRolesMapper.countUserRolesByRoleId(rolesMapper.getRoleNameId("教师")),
                userMapper.getCount()));

        List<Object> list = new ArrayList<>();
        list.add(listAdmin);
        list.add(typeList);
        return Result.ok(list);
    }
}
